/***************************************************************************
 *   Copyleft 2006-2007 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>									   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#ifndef __BSPLINEINTERPOLATION_H__
#define __BSPLINEINTERPOLATION_H__

#include <vector>
#include "../PointsSet.h"

typedef std::vector<Point4D> PointsList;
typedef std::vector<Point4D>::iterator PointsListIter;
typedef std::vector<cFloat> KnotsDistList;
typedef std::vector<cFloat>::iterator KnotsDistListIter;


class BSplineInterpolation: public PointsSet {
protected:
	struct BSplineCoefficient {
		Point4D mA;
		Point4D mB;
		Point4D mC;
		Point4D mD;
	};
	typedef std::vector<BSplineCoefficient> BSplineCoefficientList;
	typedef std::vector<BSplineCoefficient>::iterator BSplineCoefficientListIter;

	KnotsDistList mHList;
	BSplineCoefficientList mCoeffs;
	
private:
	cBool mArcLengthParametrization;
	cInt mDrawingCurvePrecision;
	cWinColor mCurveColor;

	cVoid Update();
	cVoid Interpolate();
	cVoid CalculateH();
	cVoid CalculateCoefficients(cFloat* a, cFloat* b, cFloat* c, Point4D* y);
	cVoid PrepareToRender(Matrix4D& matrix);
public:

    /**************************************************************
    * Constructors                                                *
    ***************************************************************/
    BSplineInterpolation(); 
        
    /**************************************************************
    * Operators                                                   *
    ***************************************************************/


    /**************************************************************
    * Other helpful functions                                     *
    ***************************************************************/
	virtual cVoid AddPoint(const Point4D &point);
	virtual cVoid ReplacePoint(const Point4D& point, cInt iIndex);
	virtual cVoid RemovePoint(cInt i);

	virtual cVoid Render(Renderer& renderer, Matrix4D& matrix, ProjectionPlane& plane);
	virtual cVoid Render(Renderer& renderer, Matrix4D& matrix, ProjectionPlane& plane, cWinColor color);

	virtual cVoid DisplayInfo(Renderer& renderer);
	virtual cChar* GetName();
	cVoid SwitchParametrization();
};                                                                 

#endif // __BSPLINEINTERPOLATION_H__